import { transfLonAndLat } from "@/utils/chart"
import { dateFormat } from "@/utils/date"
// import store from "@/store/index"
// import { findByvalue } from "@/utils/util"

export const option = [
  {
    label: "船名",
    prop: "shipName",
  }, {
    label: "吃水",
    prop: "draught",
    type: "filter",
    format: (row) => {
      if (row.draught >= 0 && row.draught) {
        return row.draught + "米"
      } else {
        return ""
      }
    }
  }, {
    label: "MMSI",
    prop: "mmsi"
  }, {
    label: "船长",
    prop: "length",
    type: "filter",
    format: (row) => {
      return (row.length >= 0 && row.length) ? row.length + "m" : "0m";
    }
  }, {
    label: "接收时间",
    prop: "receiveTime",
    type: "filter",
    format: (val) => {
      if (!val.receiveTime) {
        return ""
      } else {
        return dateFormat(new Date(val.receiveTime))
      }
    }
  }, {
    label: "船宽",
    prop: "width",
    type: "filter",
    format: (row) => {
      return (row.width >= 0 && row.width) ? row.width + "m" : "0m";
    }
  }, {
    label: "IMO",
    prop: "imo"
  }, {
    label: "呼号",
    prop: "callSign"
  }, {
    label: "SOG/COG",
    prop: "sogCog",
    type: "filter",
    format: (row) => {
      let speed = row.speed >= 0 ? row.speed + "kn" : "0kn";
      let course = row.course >= 0 ? row.course + "°" : "0°";
      return speed + " x " + course
    }
  }, {
    label: "艏向",
    prop: "heading",
    type: "filter",
    format: (row) => {
      if (!row.heading || row.heading === -1) {
        return ""
      } else {
        return parseInt(row.heading) + "°"
      }
    }
  }, {
    label: "预到达时间",
    prop: "eta",
    type: "filter",
    format: (val) => {
      if (!val.eta) return "暂无"
      if ((val.eta + '').length < 13) {
        val.eta = val.eta * 1000
      }
      return dateFormat(new Date(val.eta))
    }
  }, {
    label: "目的地",
    prop: "endPort",
    type: "filter",
    format: (val) => {
      if (!val.endPort) {
        return "暂无"
      } else {
        return val.endPort
      }
    }
  }, {
    label: "纬度",
    prop: "latitude",
    type: "filter",
    format: (row) => {
      if (!row.latitude) {
        return ""
      } else {
        return transfLonAndLat(row.latitude, "lat", true)
      }
    }
    // }, {
    //   label: "状态",
    //   prop: "status",
    //   type: "filter",
    //   format: (val) => {
    //     const row = findByvalue(store.state.dict.BizDict.navigation_status, val.status, {
    //       value: "dictValue",
    //       label: "dictLabel"
    //     })
    //     if (row) {
    //       return row
    //     } else {
    //       return "其他"
    //     }
    //   }
  }, {
    label: "经度",
    prop: "longitude",
    type: "filter",
    format: (row) => {
      if (!row.latitude) {
        return ""
      } else {
        return transfLonAndLat(row.longitude, "lon", true)
      }
    }
  }
]

export const initButtonState = () => {
  return {
    isWave: false,
    isLine: false,
    task: false
  }
}

export const taskOptions = [
  {
    label: "案件类型",
    prop: "caseType",
    type: "dict",
  }, {
    label: "案件区域",
    prop: "areaId",
    type: "dict",
    props: {
      value: "areaId",
      label: "areaName"
    }
  }, {
    label: "油料记录",
    prop: "currentOil",
  }, {
    label: "备注",
    prop: "dest",
  }
]

export const rules = {
  areaId: [{ required: true, message: "必填", trigger: "blur" }],
  taskName: [{ required: true, message: "必填", trigger: "blur" }],
  type: [{ required: true, message: "必填", trigger: "blur" }],
  createyouliao: [{ required: true, message: "必填", trigger: "blur" }],
  finshyouliao: [{ required: true, message: "必填", trigger: "blur" }]
};


export const initTaskForm = () => {
  return {
    areaId: "",
    remark: "",
    taskName: "",
    type: 1,
  }
}
